package pl.bizuteria.sklep.admin.client;

import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

import pl.bizuteria.sklep.admin.client.activity.mapper.AppActivityMapper;
import pl.bizuteria.sklep.admin.client.activity.mapper.CreateOrEditActivityMapper;
import pl.bizuteria.sklep.admin.client.activity.mapper.ProductActivityMapper;
import pl.bizuteria.sklep.admin.client.ui.ITwoSlotView;
import pl.bizuteria.sklep.api.shared.request.ApplicationRequestFactory;

import com.google.gwt.activity.shared.ActivityManager;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.logging.client.LogConfiguration;
import com.google.gwt.place.shared.Place;
import com.google.gwt.place.shared.PlaceChangeEvent;
import com.google.gwt.user.client.ui.RootLayoutPanel;
import com.google.inject.Inject;
import com.google.web.bindery.requestfactory.gwt.client.RequestFactoryLogHandler;
import com.google.web.bindery.requestfactory.shared.LoggingRequest;

public class DesktopApp extends App {
	private final DesktopShell shell;
	private final EventBus eventBus;
	private final AppActivityMapper appActivityMapper;
	
	
	Logger logger = Logger.getLogger(DesktopApp.class.getName());
	
	@Inject
	public DesktopApp(DesktopShell shell, EventBus eventBus,
			AppActivityMapper appActivityMapper, ProductActivityMapper productActivityMapper, CreateOrEditActivityMapper createOrEditActivityMapper, ITwoSlotView view) {
		this.shell = shell;
		this.eventBus = eventBus;
		this.appActivityMapper = appActivityMapper;
	}

	@Override
	public void run() {
		
//		if (LogConfiguration.loggingIsEnabled()) {
//			RequestFactoryLogHandler.LoggingRequestProvider provider = new RequestFactoryLogHandler.LoggingRequestProvider() {
//				public LoggingRequest getLoggingRequest() {
//					ApplicationRequestFactory requestFactory = GWT.create(ApplicationRequestFactory.class);
//					requestFactory.initialize(eventBus);
//					return requestFactory.loggingRequest();
//				}
//			};
//			Logger.getLogger("").addHandler(new RequestFactoryLogHandler(provider, Level.FINE, new ArrayList<String>()));
//		}
		
		
		eventBus.addHandler(PlaceChangeEvent.TYPE, new PlaceChangeEvent.Handler() {
		    public void onPlaceChange(PlaceChangeEvent event) {
//		      Place newPlace = event.getNewPlace();
//		      logger.info("New place fired: " + newPlace);
		    }
		  });
		
		ActivityManager activityManager = new ActivityManager(
				appActivityMapper, eventBus);
		activityManager.setDisplay(shell.simplePanel);
		
		//do bracelet list view musi byc podpiety jeden maganer
//		ActivityManager activityManagerx1 = new ActivityManager(
//				createOrEditActivityMapper, eventBus);
//		activityManagerx1.setDisplay(braceletProxyListView.slot);
		
		
		//i do earing list view tez musi byc podpiety jeden maganer!!! 
//		moga to byc inne mapery bo do braceletList jest bracelet Edit tak naprawde
//		a do earingList jest earign edit tak naprawde 
//		teraz  z tego co rozumiem moze byc np lista bracelet i edycja earing 
//		zalezy tylko jak sie mapuje place -> activity w maperze
//		ActivityManager activityManagerx2 = new ActivityManager(
//				createOrEditActivityMapper, eventBus);
//		activityManagerx2.setDisplay(earingProxyListView.slot);
		
		
		//rejestracja activity managera, gdzie to dac?????
		//list
		
		
		
		
		RootLayoutPanel.get().add(shell);
	}

	
}
